package data.goods;

import java.io.Serializable;
import java.util.ArrayList;

public class GoodsStockRecord implements Serializable{
	private boolean type;        //true import,false export
	private Goods goods;
	private String exportreason;
	private int beforeNum;
	private int beforeTypeNum=0;
	private String time;
	
	public GoodsStockRecord(boolean type, String ID, int num, 
			String startdate,String enddate,double cost,String time){
		setBeforeNum(ID);
		this.type=type;
		goods=new Goods(ID,num,startdate,enddate,cost);
		this.time=time;
		setBeforeTypeNum();
	}
	
	private void setBeforeTypeNum(){
		StockList sl=new StockList();
		ArrayList<Goods> stocks=sl.get().toArray();
		for(int i=0;i<stocks.size();i++){
			Goods temp=stocks.get(i);
			if(temp.getGoodsTypeID().equals(goods.getGoodsTypeID())){
				beforeTypeNum=beforeTypeNum+temp.getNum();
				
			}
		}
		
	}
	
	private void setBeforeNum(String ID){
		StockList sl=new StockList();
		Goods goods=sl.idFind(ID);
		if(goods!=null)
		beforeNum=goods.getNum();
		else
		beforeNum=0;
	}
	
	public GoodsStockRecord(boolean type, String ID, int num, 
			String startdate,String enddate,String exportreason,double cost,String time){
		this.type=type;
		goods=new Goods(ID,num,startdate,enddate,cost);
		this.exportreason=exportreason;
		this.time=time;
	}
	
	public boolean getType(){
		return type;
	}
	
	public String getGoodsID(){
		return goods.getID();
	}
	
	public String getGoodsName(){
		return goods.getName();
	}
	
	public String getGoodsType(){
		return goods.getType();
	}
	
	public double getGoodsPrice(){
		return goods.getPrice();
	}
	
	public int getBeforeNum(){
		return beforeNum;
	}

	
	public int getNum(){
		return goods.getNum();
	}
	
	public String getGoodsTypeID(){
		return goods.getGoodsTypeID();
	}
	
	public String getGoodsProduction(){
		return goods.getProductionDate();
	}
	public String getGoodsScrap(){
		return goods.getScrapDate();
	}

	
	public int getBeforeTypeNum(){
		System.out.println("beforeTypeNum"+beforeTypeNum);
		return beforeTypeNum;
	}
	
	public String getTime(){
		return time;
	}


}
